package br.com.hsp.system.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.hsp.organizacao.Exame;

public class ExameRepository {
private EntityManager manager ;
	
	public ExameRepository ( EntityManager manager ) {
		this.manager = manager ;
	}
	
	public void add(Exame exame) {
		this.manager.persist(exame);
	}
	
	public void remove(Long id) {
		Exame exame = this.procura(id);
		this.manager.remove(exame);
	}
	
	public Exame atualiza(Exame exame) {
		return this.manager.merge(exame);
	}
	
	public Exame procura(Long id) {
		return this.manager.find(Exame.class, id);
	}
	
	public List<Exame> getLista() {
		Query query = this.manager.createQuery("SELECT x from Exame x");
		return query.getResultList();
	}
}
